﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace emlak
{
    static class Sorgu
    {

        static private SqlConnection cnn = new SqlConnection(snfVeritabani.Connectionstring);

        static public string Olustur(snfArzArama Arzarama, RadioButton rdbIlan, RadioButton rdbAdsoyad, RadioButton rdbAdres, RadioButton rdbFiyat)
        {
            string sorgu = "";
            string kosul = "";
            string tablo = "";

            if (rdbIlan.Checked == true)
            {
                kosul = " ilanID=" + Arzarama.Ilanid.ToString();
            }
            else if (rdbAdsoyad.Checked == true)
            {
                if (Arzarama.Ad == "")
                {
                    kosul = " soyad";
                }
                else if (Arzarama.Soyad == "")
                {
                    kosul = " ad";
                }

                else
                {
                    kosul = " ad, soyad ";
                }
            }
            else if (rdbAdres.Checked == true)
            {
                if (Arzarama.Il != "")
                    kosul += " il,";
                if (Arzarama.Ilce != "")
                    kosul += " ilce,";
                if (Arzarama.Semt != "")
                    kosul += " semt,";
                kosul = kosul.Substring(0, kosul.Length - 1);
            }

            else if (rdbFiyat.Checked == true)
            {
                if (Arzarama.Islemtip == 1)
                    kosul += " kiramiktari ";
                else if (Arzarama.Islemtip == 2 || Arzarama.Islemtip == 3)
                    kosul += " fiyat1, fiyat2 ";
            }

            // tablo kısmını oluşturma

            if (Arzarama.Gayrimenkultip == 1)
                tablo = " ViewEvArz";
            else if (Arzarama.Gayrimenkultip == 2)
                tablo = " ViewIsyeriArz";
            else if (Arzarama.Gayrimenkultip == 3)
                tablo = " ViewArsaArz ";
            else
                tablo = " ViewArsaArz, ViewIsyeriArz, ViewArsaArz";

            return sorgu;
        }

        static public DataTable ArsaArzGetir_ID(int id)
        {

            cnn.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from ViewArsaArz Where ilanID= "+id.ToString()+" ",cnn);
            DataTable dt = new DataTable();

            da.Fill(dt);
            cnn.Close();
            return dt;
        }

        static public DataTable EvArzGetir_ID(int id)
        {
            cnn.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from ViewEvArz Where ilanID= " + id.ToString() + " ", cnn);
            DataTable dt = new DataTable();

            da.Fill(dt);
            cnn.Close();
            return dt;
        }

        static public DataTable IsyeriArzGetir_ID(int id)
        {
            cnn.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from ViewIsyeriArz Where ilanID= " + id.ToString() + " ", cnn);
            DataTable dt = new DataTable();

            da.Fill(dt);
            cnn.Close();
            return dt;
        }

        static public DataTable ArsaTalepGetir_ID(int id)
        {
            cnn.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from ViewArsaTalep Where ilanID= " + id.ToString() + " ", cnn);
            DataTable dt = new DataTable();

            da.Fill(dt);
            cnn.Close();
            return dt;
        }

        static public DataTable IsyeriTalepGetir_ID(int id)
        {
            cnn.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from ViewIsyeriTalep Where ilanID= " + id.ToString() + " ", cnn);
            DataTable dt = new DataTable();
            try
            {
                da.Fill(dt);
            }
            catch
            {
            }
            cnn.Close();
            return dt;
        }

        static public DataTable EvTalepGetir_ID(int id)
        {
            cnn.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from ViewEvTalep Where ilanID= " + id.ToString() + " ", cnn);
            DataTable dt = new DataTable();

            da.Fill(dt);
            cnn.Close();
            return dt;
        }

        static public DataTable KisiGetir_ID(string Tc)
        {
            cnn.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from ViewKisiler Where tc='" + Tc +"'", cnn);
            DataTable dt = new DataTable();
            


            try
            {
                da.Fill(dt);
            }
            catch (Exception)
            {
                
                throw;
            }
            
            cnn.Close();
            return dt;
        }

    }
}

